const zmfDbClient = uniCloud.importObject("zmf-db-client");
const types = {
	clear: "clear",
	// 合成信息列表
	getCompound:"getCompound",
	// 试听信息列表
	getAudition:"getAudition",
}
export default {
	namespaced: true,
	state: {
		// 合成
		compoundList: [{
			create_date:1684729143000,
			expire_date:16850714100,
			state:3,
			text:"123",
			type:1,
			uid:"6461f565e766bb00858afd8f",
			use_words:100,
			_id:"646b13f3819ce8deeef8065d"
		}],
		compoundListHasNext:true,
		// 试听
		auditionList: [],
		auditionListHasNext:true,
	},
	getters: {

	},
	mutations: {
		[types.clear](state) {
			state.compoundList = []
			state.auditionList = []
		},
		[types.getCompound](state,{userRecord,pageNum}) {
			if(userRecord !== undefined && userRecord.length > 0){
				const temp = state.compoundList
				state.compoundList = temp.concat(userRecord);
			}
			if(userRecord.length < pageNum){
				state.compoundListHasNext = false
			}
		},
		[types.getAudition](state,{userRecord,pageNum}) {
			if(userRecord !== undefined && userRecord.length > 0){
				const temp = state.auditionList
				state.auditionList = temp.concat(userRecord);
			}
			if(userRecord.length < pageNum){
				state.auditionListHasNext = false
			}
		}
	},
	actions: {
		clear({commit}) {
			commit(types.clear)
		},
		async getCompound({commit},{uid,startNum,pageNum}){
			const param = {
				uid:uid,
				type:1,
				start_num:startNum,
				page_num:pageNum
			}
			const resp = await zmfDbClient.getRecordInfoByPage(param)
			const {errCode,userRecord} = resp
			if(userRecord !== undefined && userRecord.length >= 0){
				commit(types.getCompound,{userRecord,pageNum})
			}
		},
		async getAudition({commit},{uid,startNum,pageNum}){
			const param = {
				uid:uid,
				type:2,
				start_num:startNum,
				page_num:pageNum
			}
			const resp = await zmfDbClient.getRecordInfoByPage(param)
			const {errCode,userRecord} = resp
			if(userRecord !== undefined && userRecord.length >= 0){
				commit(types.getAudition,{userRecord,pageNum})
			}
		}
		
	}
}